//
//  MyInfoView.m
//  fitnessmanage
//
//  Created by wujian on 2017/12/15.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//

#import "MyInfoView.h"

@implementation MyInfoView

-(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        UIScrollView *scrollView = [[UIScrollView alloc] init];
        [self addSubview:scrollView];
        self.scrollView = scrollView;
        
        /**
         白色背景
         */
        UIView *headWhiteView = [[UIView alloc] init];
        headWhiteView.backgroundColor = CSWhiteColor;
        [scrollView addSubview:headWhiteView];
        self.headWhiteView = headWhiteView;
        
        /**
         头像Label
         */
        UILabel *headImageLabel = [[UILabel alloc] init];
        headImageLabel.text = @"头像";
        headImageLabel.font = MidBigFont;
        headImageLabel.textColor = CSColorFromRGB(0x666666);
        [headWhiteView addSubview:headImageLabel];
        self.headImageLabel = headImageLabel;
        
        /**
         按钮
         */
        UIButton *headBtn = [[UIButton alloc] init];
        headBtn.layer.cornerRadius = 40;
        headBtn.layer.masksToBounds = YES;
        headBtn.imageView.contentMode = UIViewContentModeScaleAspectFill;
        headBtn.imageView.layer.masksToBounds = YES;
        [headBtn setImage:PlaceHold forState:UIControlStateNormal];
        [headWhiteView addSubview:headBtn];
        self.headBtn = headBtn;
        
        UIImageView *rightImageView = [[UIImageView alloc] init];
        rightImageView.image = [UIImage imageNamed:@"xiayibu"];
        [headWhiteView addSubview:rightImageView];
        self.rightImageView = rightImageView;
        
        /**
         用户名
         */
        CommonInputView *nameInputView = [[CommonInputView alloc] init];
        nameInputView.titleLabel.text = @"用户名*";
        nameInputView.titleTF.placeholder = @"请输入用户名";
        [scrollView addSubview:nameInputView];
        self.nameInputView = nameInputView;
        
        CommonInputView *realNameInputView = [[CommonInputView alloc] init];
        realNameInputView.titleLabel.text = @"真实姓名*";
//        realNameInputView.titleTF.userInteractionEnabled = NO;
        [scrollView addSubview:realNameInputView];
        self.realNameInputView = realNameInputView;
        
        /**
         微信
         */
        CommonInputView *weChatInputView = [[CommonInputView alloc] init];
        weChatInputView.titleLabel.text = @"微信*";
        weChatInputView.titleTF.placeholder = @"微信";
        [scrollView addSubview:weChatInputView];
        self.weChatInputView = weChatInputView;
        
        /**
         性别
         */
        CommonBtnView *sexBtnView = [[CommonBtnView alloc] init];
        sexBtnView.titleLabel.text = @"性别*";
        sexBtnView.choseLabel.text = @"选择性别";
        sexBtnView.choseLabel.textColor = PlaceHoldColor;
        [scrollView addSubview:sexBtnView];
        self.sexBtnView = sexBtnView;
        
        /**
         性别
         */
        CommonBtnView *addressBtnView = [[CommonBtnView alloc] init];
        addressBtnView.titleLabel.text = @"城市*";
        addressBtnView.choseLabel.text = @"选择城市";
        addressBtnView.choseLabel.textColor = PlaceHoldColor;
        [scrollView addSubview:addressBtnView];
        self.addressBtnView = addressBtnView;
        
        /**
         擅长
         */
        CommonBtnView *longBtnView = [[CommonBtnView alloc] init];
        longBtnView.titleLabel.text = @"擅长";
//        longBtnView.choseLabel.text = @"选择城市";
        longBtnView.choseLabel.textColor = PlaceHoldColor;
        longBtnView.rightImageView.image = [UIImage imageNamed:@"icon_add"];
        longBtnView.lineView.hidden = YES;
        [scrollView addSubview:longBtnView];
        self.longBtnView = longBtnView;
        
        /**
         放擅长
         */
        CommonInputView *longView = [[CommonInputView alloc] init];
        longView.titleTF.userInteractionEnabled = NO;
        [scrollView addSubview:longView];
        self.longView = longView;
        
        UIScrollView *longScroollView = [UIScrollView new];
        self.longScrollView = longScroollView;
        [longView addSubview:longScroollView];
        
        //第三方标签布局的视图
        SKTagView *tagView = [[SKTagView alloc] init];
        // 整个tagView对应其SuperView的上左下右距离
        tagView.padding = UIEdgeInsetsMake(5, 5, 5, 5);
        // 上下行之间的距离
        tagView.lineSpacing = 10;
        // item之间的距离
        tagView.interitemSpacing = 15;
        // 最大宽度
        tagView.preferredMaxLayoutWidth = CGFLOAT_MAX ;
        //        tagView.regularWidth = kScreenWidth - 80;
        //    @property (assign, nonatomic) CGFloat regularWidth; //!< 固定宽度
        //    @property (nonatomic,assign ) CGFloat regularHeight; //!< 固定高度
        // 原作者没有能加固定宽度的，自己修改源码加上了固定宽度和高度,默认是0，就是标签式布局，如果实现了，那么就是固定宽度高度
        //    self.tagView.regularWidth = 100;
        //            tagView.regularHeight = 30;
        [self.longScrollView addSubview:tagView];
        
        self.tagView = tagView;
        
        //随便说
        CZQCustonTextView *talkView = [CZQCustonTextView new];
        talkView.placeLable.text = @"一句话简介";
//        talkView.toolPlaceLable.text = @"0/30字";
        talkView.max = 30;
        self.talkView = talkView;
        [scrollView addSubview:talkView];
        
        
        
        UIButton *sureBtn = [[UIButton alloc] init];
        [sureBtn setTitle:@"保存"];
        [sureBtn setTitleColor:CSColorFromRGB(0x0a0a0a)];
        sureBtn.titleLabel.font = MidBigFont;
        sureBtn.backgroundColor = ButtonBackGroundColor;
        [scrollView addSubview:sureBtn];
        self.sureBtn = sureBtn;
        
        [self setConstraints];
    }
    
    return self;
}

-(void)setConstraints{
    
    [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.mas_equalTo(self);
    }];
    
    /**
     白色背景
     */
    [self.headWhiteView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.left.width.mas_equalTo(self.scrollView);
    }];
    
    /**
     头像Label
     */
    [self.headImageLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_equalTo(self.headWhiteView);
        
        make.left.mas_equalTo(self.headWhiteView).offset(20);
    }];
    
    /**
     按钮
     */
    [self.headBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(self.rightImageView.mas_left).offset(-10);

        make.width.height.mas_equalTo(80);
        
        make.top.mas_equalTo(self.headWhiteView).offset(15);
        
        make.bottom.mas_equalTo(self.headWhiteView).offset(-15);
    }];
    
    [self.rightImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.centerY.mas_equalTo(self.headWhiteView);
        
        make.right.mas_equalTo(self.headWhiteView).offset(-15);
    }];
    
    /**
     用户名
     */
    [self.nameInputView mas_remakeConstraints:^(MASConstraintMaker *make) {

        make.top.mas_equalTo(self.headWhiteView.mas_bottom).offset(10);

        make.left.width.mas_equalTo(self);
    }];

    [self.realNameInputView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.nameInputView.mas_bottom);
        
        make.left.width.mas_equalTo(self);
    }];
    
    /**
     性别
     */
    [self.sexBtnView mas_remakeConstraints:^(MASConstraintMaker *make) {

        make.top.mas_equalTo(self.realNameInputView.mas_bottom);

        make.left.width.mas_equalTo(self);
    }];

    /**
     地址
     */
    [self.addressBtnView mas_remakeConstraints:^(MASConstraintMaker *make) {

        make.top.mas_equalTo(self.sexBtnView.mas_bottom);

        make.left.width.mas_equalTo(self);
    }];
    
    //微信
    [self.weChatInputView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.addressBtnView.mas_bottom);
        
        make.left.width.mas_equalTo(self);
    }];
    
    //擅长
    [self.longBtnView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.weChatInputView.mas_bottom);
        
        make.left.width.mas_equalTo(self);
    }];
    
    [self.longView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.longBtnView.mas_bottom);
        
        make.left.width.mas_equalTo(self);
        
        make.height.mas_equalTo(1);
        
    }];
    
    [self.longScrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(self.longView);
        
    }];
    
    [self.tagView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.bottom.mas_equalTo(self.longScrollView);
        make.left.mas_equalTo(self.longScrollView).offset(15);
        make.right.mas_equalTo(self.longScrollView).offset(-10);
        
    }];
    
    
    //一句话简介
    [self.talkView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.longView.mas_bottom);
        
        make.left.width.mas_equalTo(self);
        
        make.height.mas_equalTo(100);
        
    }];


    [self.sureBtn mas_remakeConstraints:^(MASConstraintMaker *make) {

        make.top.mas_equalTo(self.talkView.mas_bottom).offset(10);

        make.left.mas_equalTo(self.scrollView).offset(20);

        make.right.mas_equalTo(self).offset(-20);

        make.height.mas_equalTo(50);
    }];
    
}

-(void)setLongArrM:(NSMutableArray *)longArrM
{
    _longArrM = longArrM;
    
    WS(weakSelf);
    
    if (longArrM.count > 0) {
        
        [_tagView removeAllTags];
        // 开始加载
        [longArrM enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            // 初始化标签
            SKTag *tag = [[SKTag alloc] initWithText:longArrM[idx]];
            // 标签相对于自己容器的上左下右的距离
            tag.padding = UIEdgeInsetsMake(5, 10, 5, 10);
            // 弧度
            tag.cornerRadius = 3.0f;
            // 字体
            tag.font = [UIFont boldSystemFontOfSize:13];
            // 边框宽度
            tag.borderWidth = 1;
            // 背景
            //        tag.bgColor = [UIColor colorWithRed:244/255.0 green:244/255.0 blue:244/255.0 alpha:1];
            // 边框颜色
            tag.borderColor = CSColorFromRGB(0xdbdbdb);
            // 字体颜色
            tag.textColor = BlackColor;
            // 是否可点击
            tag.enable = YES;
            // 加入到tagView
            [weakSelf.tagView addTag:tag];
            
            if (idx == weakSelf.longArrM.count -1) {
                
            }
        }];
        
        [self.longView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.mas_equalTo(self.longBtnView.mas_bottom);
            
            make.left.width.mas_equalTo(self);
            
            make.height.mas_equalTo(50);
            
        }];
        
        self.longScrollView.contentSize = CGSizeMake(_tagView.right, 0);
        
    }else
    {
        
        [self.longView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.top.mas_equalTo(self.longBtnView.mas_bottom);
            
            make.left.width.mas_equalTo(self);
            
            make.height.mas_equalTo(1);
            
        }];
        
        self.longScrollView.contentSize = CGSizeMake(0, 0);
        
    }
    
    [self setNeedsLayout];
    [self setNeedsDisplay];
    
}

-(void)layoutSubviews{
    
    self.scrollView.contentSize = CGSizeMake(self.width, self.sureBtn.bottom + 20);
}

@end
